<script lang="ts" setup>
import type { Config } from "@i18n/index"
import type { Lanuage } from "@i18n/language";
import { setLocal } from "@util/index"

const i18n = inject<Config<Lanuage>>("i18n")
const changeLanguage = (val: "cn" | "en") => {
  i18n!.target = val
  setLocal("__LANGUAGE__", i18n!.target)
}
const showList = ref(false)
const showTrigger = ref(false)
</script>

<template>
  <nav class="nav">
    <div class="logo" @click="$router.push('/')">
      <i>IMAGE</i>
      <img src="/logo.svg" alt="logo read error" draggable="false" />
    </div>
    <div class="info">
      <div class="language">
        <p>{{i18n!.target === "cn" ? "简体中文" : "English"}}</p>
        <img src="/down.svg" alt="img read error" draggable="false" />
        <div class="choose-box">
          <p @click="changeLanguage('cn')">简体中文</p>
          <p @click="changeLanguage('en')">English</p>
        </div>
      </div>
      <router-link to="/feedback">{{$t("nav.feedback")}}</router-link>
      <router-link to="/about">{{$t("nav.about")}}</router-link>
      <router-link to="/mine">{{$t("nav.mine")}}</router-link>
    </div>
    <div class="info-phone">
      <img :style="{transform: showList ? 'rotate(90deg)' : 'rotate(0)'}" src="/options.svg" alt="img load error"
        @click="showList = !showList">
      <div class="show-list" v-show="showList">
        <div class="language">
          <div class="choose-tag" @click="showTrigger = !showTrigger">
            <p>{{i18n!.target === "cn" ? "简体中文" : "English"}}</p>
            <img :style="{transform: showTrigger ? 'rotate(0)' : 'rotate(180deg)'}" src="/down.svg" alt="img read error"
              draggable="false" />
          </div>
          <div class="choose-box" v-show="showTrigger" @click="showList = false">
            <p :class="i18n!.target === 'cn' && 'active'" @click="changeLanguage('cn')">简体中文</p>
            <p :class="i18n!.target === 'en' && 'active'" @click="changeLanguage('en')">English</p>
          </div>
        </div>
        <router-link @click="showList = false" to="/feedback">{{$t("nav.feedback")}}</router-link>
        <router-link @click="showList = false" to="/about">{{$t("nav.about")}}</router-link>
        <router-link @click="showList = false" to="/mine">{{$t("nav.mine")}}</router-link>
      </div>
    </div>
  </nav>
</template>

<style lang="scss" scoped>
@media screen and (min-width: 768px) {
  .nav {
    .logo {
      margin: 0 auto;
      transform: translateX(100px)
    }

    .info {
      @include vC;
    }

    .info-phone {
      display: none;
    }

  }
}

@media screen and (max-width: 767px) {
  .nav {
    @include vC;

    .logo {
      margin: 0 auto;
    }

    .info {
      display: none;
    }

    .info-phone {
      position: relative;

      img {
        width: 30px;
        height: 30px;
        margin-right: 24px;
        transition: transform .25s;
        cursor: pointer;
      }

      .show-list {
        width: 115px;
        color: $headBg;
        position: absolute;
        top: 150%;
        right: 30px;
        background-color: #fff;
        padding: 12px 8px;
        border-radius: 8px;

        .language {
          border-bottom: 1px solid rgba(60, 60, 60, .12);
          cursor: pointer;

          .choose-tag {
            @include vC;
            flex-wrap: nowrap;
            padding: 12px 0 11px;

            p {
              white-space: nowrap;
            }

            img {
              width: 12px;
              height: 12px;
              margin-left: 8px;
              transition: transform .25s;
            }
          }

          .choose-box {
            margin-left: 16px;

            p {
              margin-bottom: 12px;
            }

            .active {
              color: $themeColor;
            }
          }
        }

        a {
          display: block;
          border-bottom: 1px solid rgba(60, 60, 60, .12);
          padding: 12px 0 11px;
        }

        a:hover {
          color: $themeColor;
        }
      }
    }

    a {
      color: $headBg;
    }
  }
}

.nav {
  height: 100%;
  display: flex;

  .logo {
    @include vC;
    cursor: pointer;

    i {
      font-size: 38px;
      background: var(--home-background);
      -webkit-background-clip: text;
      background-clip: text;
      -webkit-text-fill-color: var(--home-color);
    }

    img {
      width: 40px;
      height: 40px;
      margin-left: 16px;
    }
  }

  .info {
    padding-right: 28px;

    img {
      width: 16px;
      height: 16px;
      margin-left: 4px;
      transform: rotate(180deg);
    }

    p,
    a {
      line-height: 16px;
      color: #fff;
    }

    &>a {
      @include vC;
      height: 100%;
      position: relative;
      cursor: pointer;
      margin-left: 16px;
    }

    &>a:hover {
      color: $themeColor;
    }


    .language {
      @include vC;
      height: 100%;
      cursor: pointer;
      position: relative;

      .choose-box {
        position: absolute;
        top: 100%;
        background-color: var(--choose-box-bg);
        box-shadow: 0 12px 32px rgba(255, 255, 255, .1), 0 2px 6px rgba(255, 255, 255, .08);
        border-radius: 8px;
        @include center;
        flex-direction: column;
        padding-bottom: 12px;
        visibility: hidden;
        opacity: 0;
        transform: translateY(-4px);
        transition: opacity .25s, visibility .25s, transform .25s;

        p {
          padding-top: 18px;
          margin: 0 12px;
          white-space: nowrap;
        }

        p:hover {
          color: $themeColor;
        }
      }
    }

    .language:hover,
    .choose-box:hover {
      .choose-box {
        visibility: visible;
        opacity: 1;
        transform: translateY(0);
      }
    }

    .language:hover {
      &>p {
        color: $themeColor;
      }
    }
  }

}
</style>

